var categorys = {
    'dataSource': {
        title: '数据源节点', child: [
            {
                name: 'start',
                title: '开始',
                icon: '<img class="icon" src="../../../skins/plugins/flow-editor/img/node/start.png" style="height: 15px;">',
                selected: ['control', 'query', 'rule', 'ruleSet', 'assign'],
                status: 0,
                fontStyle: {
                    fontFamily: "微软雅黑",
                    size: 13,
                    color: "255,255,255",
                    bold: false,
                    italic: false,
                    underline: false,
                    textAlign: "center",
                    vAlign: "middle",
                    orientation: "vertical"
                },
                lineStyle: {
                    lineWidth: 1,
                    lineColor: "228,75,78",
                    lineStyle: "solid"
                },
                fillStyle: {
                    type: "solid",
                    color: "228,75,78"
                },
            }
        ]
    },
    'control': {
        title: '控制节点', child: [
            {
                name: 'control',
                title: '条件节点',
                icon: '<img class="icon" src="../../../skins/plugins/flow-editor/img/node/control.png" style="height: 15px;">',
                selected: ['control', 'query', 'rule', 'ruleSet', 'assign', 'output'],
                status: 0,
                fontStyle: {
                    fontFamily: "微软雅黑",
                    size: 13,
                    color: "24, 144, 255",
                    bold: false,
                    italic: false,
                    underline: false,
                    textAlign: "left",
                    vAlign: "middle",
                    orientation: "vertical"
                },
                lineStyle: {
                    lineWidth: 1,
                    lineColor: "24, 144, 255",
                    lineStyle: "solid"
                },
                fillStyle: {
                    type: "solid",
                    color: "227,239,250"
                },
            },
        ]
    },

    'execute': {
        title: '执行节点', child: [
            {
                name: 'query',
                title: '查询节点',
                icon: '<img class="icon" src="../../../skins/plugins/flow-editor/img/node/query.png" style="height: 15px;">',
                selected: [],
                status: 0,
                fontStyle: {
                    fontFamily: "微软雅黑",
                    size: 13,
                    color: "228, 75, 78",
                    bold: false,
                    italic: false,
                    underline: false,
                    textAlign: "left",
                    vAlign: "middle",
                    orientation: "vertical"
                },
                lineStyle: {
                    lineWidth: 1,
                    lineColor: "228, 75, 78",
                    lineStyle: "solid"
                },
                fillStyle: {
                    type: "solid",
                    color: "247,232,233"
                },
            },
            // { name: 'rule', title: '规则', icon: '<i class="icon fa fa-share-alt"></i>', selected: [], status: 0 },
            // { name: 'ruleSet', title: '规则集', icon: '<i class="icon fa fa-share-alt-square"></i>', selected: [], status: 0 },
            // { name: 'assign', title: '赋值节点', icon: '<i class="icon fa fa-facebook"></i>', selected: [], status: 0 },
            {
                name: 'output',
                title: '输出节点',
                icon: '<img class="icon" src="../../../skins/plugins/flow-editor/img/node/output.png" style="height: 15px;">',
                selected: [],
                status: 1,
                fontStyle: {
                    fontFamily: "微软雅黑",
                    size: 13,
                    color: "228, 75, 78",
                    bold: false,
                    italic: false,
                    underline: false,
                    textAlign: "left",
                    vAlign: "middle",
                    orientation: "vertical"
                },
                lineStyle: {
                    lineWidth: 1,
                    lineColor: "228, 75, 78",
                    lineStyle: "solid"
                },
                fillStyle: {
                    type: "solid",
                    color: "247,232,233"
                },
            }
        ]
    }
};

$.each(categorys, function (k, v) {
    Schema.addCategory({
        name: k,
        text: v.title,
        dataAttributes: []
    });
    $.each(v.child, function () {
        var key = this.name;
        if (this.name === 'start') {
            Schema.addShape({
                name: this.name,
                title: this.title,
                category: k,
                icon: this.icon,
                selected: this.selected,
                fontStyle: this.fontStyle,
                lineStyle: this.lineStyle,
                fillStyle: this.fillStyle,
                props: { w: 150, h: 40, },
                path: [{
                    actions: [{ action: "move", x: "Math.min(w,h)/2.5", y: "0" },
                        { action: "line", x: "w-Math.min(w,h)/2.5", y: "0" },
                        { action: "curve", x1: "w+Math.min(w,h)/2.5/2.5", y1: "0", x2: "w+Math.min(w,h)/2.5/2.5", y2: "h", x: "w-Math.min(w,h)/2.5", y: "h" },
                        { action: "line", x: "Math.min(w,h)/2.5", y: "h" },
                        { action: "curve", x1: "-Math.min(w,h)/2.5/2.5", y1: "h", x2: "-Math.min(w,h)/2.5/2.5", y2: "0", x: "Math.min(w,h)/2.5", y: "0" },
                        { action: "close" }]
                }]
            });
        } else {
            Schema.addShape({
                name: this.name,
                title: this.title,
                category: k,
                icon: this.icon,
                selected: this.selected,
                fontStyle: this.fontStyle,
                lineStyle: this.lineStyle,
                fillStyle: this.fillStyle,
                props: { w: 150, h: 40, },
                path: [{
                    actions: [{ action: "move", x: "Math.min(w,h)/5/5", y: "0" },
                        { action: "line", x: "w-Math.min(w,h)/5/5", y: "0" },
                        { action: "curve", x1: "w+Math.min(w,h)/5/5", y1: "0", x2: "w+Math.min(w,h)/5/5", y2: "h", x: "w-Math.min(w,h)/5/5", y: "h" },
                        { action: "line", x: "Math.min(w,h)/5/5", y: "h" },
                        { action: "curve", x1: "-Math.min(w,h)/5/5", y1: "h", x2: "-Math.min(w,h)/5/5", y2: "0", x: "Math.min(w,h)/5/5", y: "0" },
                        { action: "close" }]
                }]
            });
        }

        var temp = $('#configure .template');
        var _div = temp.find('#temp_' + key);
        if (_div.length == 0 && this.formEL) {
            temp.append('<div id="temp_' + key + '"></div>');
            _div = temp.find('#temp_' + key);
            $.each(this.formEL, function () {
                var require = ' <font>*</font>', required = 'required', tipHtml = '<i title_pos="left" title="' + (this.tips || '') + '" class="fa fa-question-circle"></i>';
                if (this.hide) required = '';
                if (this.require == false) require = '';
                if (!this.tips) tipHtml = '';

                var startHtml = '<div class="layui-form-item ' + this.name + '">' + '<label class="layui-form-label">' + this.title + require + '</label>' + '<div class="layui-input-block">';
                var endHtml = '</div></div>';

                //title="'+this.title+'"
                if (this.type == 'select') {
                    _div.append(startHtml
                        + '<select name="' + this.name + '" lay-verify="' + required + '|' + this.name + '" lay-filter="' + (this.filter || '') + '"><option value="">请选择...</option></select>'
                        + tipHtml + endHtml);
                    var select = _div.find('select[name="' + this.name + '"]');
                    if (this.child)
                        var nn = this.name;
                    $.each(this.child, function () {
                        select.append('<option value="' + this.value + '" xx="{{ d.' + nn + '==\'' + this.value + '\'?\'selected\':\'\' xx}}">' + this.text + '</option>');
                    });
                } else if (this.type == 'textarea') {
                    _div.append(startHtml
                        + '<textarea name="' + this.name + '" class="layui-textarea" lay-verify="' + required + '|' + this.name + '" placeholder="请输入' + this.title + '" class="layui-input">{{ d.' + this.name + '||\'\' }}</textarea>'
                        + tipHtml + endHtml);
                } else {
                    var num = this.type;
                    if (this.type != "number") num = '';
                    _div.append(startHtml
                        + '<input type="' + this.type + '" name="' + this.name + '" value="{{ d.' + this.name + '||\'\' }}" lay-verify="' + required + '|' + (this.name + '|' + num) + '" placeholder="请输入' + this.title + '" class="layui-input" />'
                        + tipHtml + endHtml);
                }
                if (this.hide) {
                    _div.find('.' + this.name).hide();
                }
            });
        }
    });
});
